<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	{js:jquery}
	{js:validate}
	{js:dialog}
	{js:form}
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<link href="{webroot:public/css/twitter-bootstrap/3.3.7/css/bootstrap.min.css}" rel="stylesheet">
	<script src="{webroot:public/javascript/public.js}"></script>
</head>

<body>
<div class="container">
	<form action="{url:/seller/live_recommend_goods_update}" method="post" name="">
		<input name='id' type='hidden' />
		<table class="table">
			<colgroup>
				<col width="180px" />
				<col />
			</colgroup>

			<tr>
				<th>标题：</th>
				<td>
					<input name='title' type='text' class='form-control' pattern='required' />
					<span class='help-block'>直播推荐标题</span>
				</td>
			</tr>

			<tr>
				<th>选择商品：</th>
				<td>
					<input type='hidden' name='goods_id' />
					<input type='button' class='btn btn-info' onclick='searchGoods({"seller_id":{$seller_id},"callback":searchGoodsCallback});' value="添加商品" />
					<label class="tip">* 添加要推荐的商品</label>
				</td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<td id='goods_box'>
				</td>
			</tr>
			<tr>
				<th>排序：</th>
				<td>
					<input name='sort' type='text' class='form-control' pattern='required' />
					<span class='help-block'>直播推荐商品排序</span>
				</td>
			</tr>


			<tr>
				<td></td>
				<td>
					<input type="submit" class="btn btn-success" value="保 存" />
					<input type="button" class="btn btn-danger" value="返 回" onclick="window.location.href='{url:/seller/live_recommend_goods}';" />
				</td>
			</tr>
		</table>
	</form>
</div>
<script type="text/javascript">
jQuery(function()
{
	var formObj = new Form();
	formObj.init({echo:JSON::encode($data)});

    //关联商品信息
    {if:isset($goodsRow)}
    relationCallBack({$goodsRow},"{$goodsRow['img']}");
    {/if}
});

//输入筛选商品的条件
function searchGoodsCallback(goodsList)
{
    goodsList.each(function()
    {
        var temp = $.parseJSON($(this).attr('data'));
        var content = {
            "data":
                {
                    "id":temp.goods_id,
                    "name":temp.name,
                    "img":temp.img,
                    "sell_price":temp.sell_price,
                    "img":temp.img,
                    "store_nums":temp.store_nums
                }
        };
        relationCallBack(content);
    });
}

//关联商品回调处理函数
function relationCallBack(content,regimentImg)
{
    if(content)
    {
        $('[name="goods_id"]').val(content['data']['id']);
        regimentImg = !regimentImg ? content['data']['img'] : regimentImg;
        var imgUrl  = webroot(regimentImg);
        var html = '<tr><th>商品名称：</th><td>'+content['data']['name']+'</td></tr>'
            +'<tr><th>展示图片：</th><td><img src="'+imgUrl+'" title="'+content['data']['name']+'" style="max-width:140px;" /><p></tr>';
        $('#goods_box').html(html);
    }
}
</script>
</body>
</html>